//
//  ViewController.m
//  10-易车
//
//  Created by dllo on 16/7/27.
//  Copyright © 2016年 LST. All rights reserved.
//

#import "ViewController.h"
#import "LMCycleView.h"
#import "NetworkHandler.h"
#import "Model.h"
#import "CycleImageTableViewCell.h"
#import "ListTableViewCell.h"
#import "ListModel.h"
#define WIDTH self.view.bounds.size.width
#define HEIGHT self.view.bounds.size.height
@interface ViewController ()<LMCycleViewDelegate, UITableViewDelegate, UITableViewDataSource>
@property(nonatomic, strong) LMCycleView *cysleView;
@property (nonatomic,strong)NSArray * arrModels;
@property (nonatomic, strong)NSArray *arr;
@property (nonatomic, retain) UITableView *tableView;

@end

@implementation ViewController
- (NSArray *)arrModels{
    if (!_arrModels) {
        self.arrModels = [NSArray array];
    }
    return _arrModels;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.arr = [NSArray array];
    self.view.backgroundColor = [UIColor yellowColor];
    NSArray *arr = [Model getDataFromPlist];
    NSMutableArray *arrIma = [NSMutableArray array];
    for (Model *model in arr) {
        [arrIma addObject:model.picCover];
    }
    self.arrModels = arrIma;
    self.arr = [ListModel getDataFromPlist];
    //初始化滚动视图对象:
    self.cysleView = [[LMCycleView alloc] initWithFrame:CGRectMake(0, 0, WIDTH, HEIGHT / 3.68) DataSource:_arrModels TimeInterval:1.5];
    _cysleView.delegate = self;
    [self.view addSubview:_cysleView];
    [self creatTableView];
}
- (void)creatTableView {
    self.tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, WIDTH, HEIGHT) style:0];
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    self.tableView.tableHeaderView =self.cysleView;
    [self.view addSubview:self.tableView];
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.arr.count;
}

-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.row == 0) {
        static NSString *ID = @"cell";
        CycleImageTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];
        if (cell ==nil) {
            cell = [[CycleImageTableViewCell alloc]initWithStyle:1 reuseIdentifier:@"cell"];
        }
        return cell;
    } else {
        static NSString *IDD = @"cell2";
        ListTableViewCell *cell2 = [tableView dequeueReusableCellWithIdentifier:IDD];
        if (cell2 ==nil) {
            cell2 = [[ListTableViewCell alloc]initWithStyle:0 reuseIdentifier:IDD];
        }
        ListModel *model = self.arr[indexPath.row];
        cell2.model = model;
        return cell2;
    }
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.row == 0) {
        return 80;
    }else{
        return 150;
    }
}
@end
